package com.bookcode.dao;

import com.bookcode.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface BookDao extends JpaRepository<Book, Integer>, JpaSpecificationExecutor<Book> {
    @Query(value = "select * from t_book where t_book.name like  %?1% ",nativeQuery = true)
// 或者 @Query("select b from Book b where b.name like %?1%")
    public List<Book> findByName(String name);
    //  nativeQuery默认是hql查询，true表示使用本地查询，就是原生的sql方式
    @Query(value = "select * from t_book  ORDER BY RAND( ) limit ?1 ",nativeQuery = true)
    public List<Book> randomList(Integer id);
}
